package com.abocode.aichat.server.context.delivery;

import com.abocode.aichat.server.context.ServerRuntimeContext;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author guanxf
 */
public abstract class AbstractServerDeliver<T> implements ServerDeliver<T> {

    protected ExecutorService executor;

    private ServerRuntimeContext serverRuntimeContext;

    @Override
    public ServerRuntimeContext getServerRuntimeContext() {
        return serverRuntimeContext;
    }

    @Override
    public void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext) {
        this.serverRuntimeContext = serverRuntimeContext;
    }

    protected AbstractServerDeliver() {
        int coreThreadCount = 10;
        int maxThreadCount = 20;
        int threadTimeoutSeconds = 2 * 60 * 1000;
        this.executor = new ThreadPoolExecutor(coreThreadCount, maxThreadCount, threadTimeoutSeconds, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
    }
}
